#ifndef RK322_OVERLAYAPI_H
#define RK322_OVERLAYAPI_H
/**
98992283  e_rk_overlay_shm_isbostcast
98992262  g_overlayInfo
**/
#include <stdio.h>
#include <linux/input.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <X11/Xlib.h>



enum {
	HAL_PIXEL_FORMAT_RGBA_8888 = 1,
	HAL_PIXEL_FORMAT_RGBX_8888 = 2,
	HAL_PIXEL_FORMAT_RGB_888 = 3,
	HAL_PIXEL_FORMAT_RGB_565 = 4,
	HAL_PIXEL_FORMAT_BGRA_8888 = 5,
	HAL_PIXEL_FORMAT_RGBA_5551 = 6,
	HAL_PIXEL_FORMAT_RGBA_4444 = 7,

	HAL_PIXEL_FORMAT_YV12 = 0x32315659,	// YCrCb 4:2:0 Planar

	/* Legacy formats (deprecated), used by ImageFormat.java */

	/*
	 * YCbCr format default is BT601.
	 */
	HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10,	// NV16
	HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11,	// NV21
	HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14,	// YUY2
	HAL_PIXEL_FORMAT_YCrCb_NV12 = 0x20,	// YUY2
	HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO = 0x21,	// YUY2
	
	HAL_PIXEL_FORMAT_YCrCb_NV12_10	    = 0x22, // YUV420_1obit
	HAL_PIXEL_FORMAT_YCbCr_422_SP_10	= 0x23, // YUV422_1obit
	HAL_PIXEL_FORMAT_YCrCb_444_SP_10	= 0x24, //YUV444_1obit

	HAL_PIXEL_FORMAT_YCrCb_444 = 0x25,	//yuv444
	HAL_PIXEL_FORMAT_FBDC_RGB565	= 0x26,
	HAL_PIXEL_FORMAT_FBDC_U8U8U8U8	= 0x27, /*ARGB888*/
	HAL_PIXEL_FORMAT_FBDC_U8U8U8	= 0x28, /*RGBP888*/
	HAL_PIXEL_FORMAT_FBDC_RGBA888	= 0x29, /*ABGR888*/
	HAL_PIXEL_FORMAT_BGRX_8888 = 0x30,
	HAL_PIXEL_FORMAT_BGR_888 = 0x31,
	HAL_PIXEL_FORMAT_BGR_565 = 0x32,

	HAL_PIXEL_FORMAT_YUYV422 = 0x33,
	HAL_PIXEL_FORMAT_YUYV420 = 0x34,
	HAL_PIXEL_FORMAT_UYVY422 = 0x35,
	HAL_PIXEL_FORMAT_UYVY420 = 0x36,

	BYWAN_PIXEL_FORMAT_YV12_T_NV12,
	BYWAN_PIXEL_FORMAT_422P_T_422SP
	//========================//

};
#define HAL_PIXEL_FORMAT_NV12 HAL_PIXEL_FORMAT_YCrCb_NV12



typedef struct cursor_tcp_{
    int width;
    int height;
    int flag;
    int hostX;
    int hostY;
}*hcursor_tcp,cursor_tcp;
/**/
enum {
HWC_SIZE_32X32 = 0,
HWC_SIZE_64X64,
HWC_SIZE_96X96,
HWC_SIZE_128X128,
};




//=================shm====================//
#define GRADECAPACITY 20
typedef struct shmOverlayGrade_{
	int pid;
	int grade;
	int isOnline;
}SMOVERLAYGRADE;
typedef struct shmOverlayInfo_{
int displayX;
int displayY;
int displayW;
int displayH;
int dataX;
int dataY;
int dataW;
int dataH;
int imWidth;
int imHeight;
int stepW;
int stepH;
int pixformat;



int isOverCur;
int xhotspot;
int yhotspot;

int overCurLastX;
int overCurLastY;
int overCurLastW;
int overCurLastH;
int overCurLastXhot;
int overCurLastYhot;

int ishwcopen;


//----constant----//
char * fb0mem;
char * overlayAddr_fb1_1;
char * overlayAddr_fb1_2;
char * overlayAddr_fb1_hwc;


int fbwidth;
int fbheight;
int fbavglen;


//----extra----//
int isX11vncConnect;


int proQuantity;
SMOVERLAYGRADE gradearry[GRADECAPACITY]; 

}SHMOVERLAYINFO;


enum{
	OVERLAY_GRADESTD_UNKNOW		= 0,
	OVERLAY_GRADESTD_XFDPFB		= 3,	
	OVERLAY_GRADESTD_MPLAYER	= 10,
	OVERLAY_GRADESTD_LOCALWIN	= 12,
	OVERLAY_GRADESTD_BROADCAST	= 19,
	OVERLAY_GRADESTD_FB1DOWN	= 20
};



//===================variable=================//
extern char *overlayAddr_fb1_c;
extern int *e_rk_overlay_shm_isbostcast;
extern int e_rk_defaultCursorBgra32x32[];
extern int e_rk_defaultCursorBgra41x39[];

extern char e_rk_cursor_buf[];
#define e_rk_overlay_curDataEx overlayAddr_fb1_c




//====================api===================//

/**
*api init  ,You need to init before you can use any other API.
*int grade : grade = hwc|over;  if program1:over > program2:over then program1 call api can sucess
*/
int rk_overlay_hwcursor_init(int grade);

/**
*Corresponding to rk_overlay_hwcursor_init
*Execute before program exit
*/
int rk_overlay_hwcursor_uninit();

/**
*Hide the overlay and grade invalid
*/
int rk_overlay_disableDisplay();

/**
*grade valid
*/
int rk_overlay_enableDisplay();


/**
*change overlay Rect
*/
int rk_overlay_setRect(int dec_x , int dec_y , int dec_width , int dec_height);

/**
*change overlay rece and overlay format ,and update fb data
*char **data , if format=NV12 then data[0] = char *y  data[1] = char *uv,
*char **data , if format=yv12 then data[0] = char *y  data[1] = char *u data[2] = char *v
*example rk_overlay_display(0,0,1920,1080,  0,0,1366,768,  data , 1366,768 ,1376,768,HAL_PIXEL_FORMAT_YCrCb_NV12);
*/
int rk_overlay_display(int dec_x, int dec_y ,int dec_width , int dec_height , 
							int src_x , int src_y ,int src_width , int src_height , 
							char **data , int width, int height , int stepW , int stepH,int format );


int rk_overlay_state(int state);
int rk_overlay_isGradeToActive();
int rk_overlay_isHwcActive();
int rk_overlay_setOvlFormat(int pixformat , int ovl_x , int ovl_y , int ovl_w , int ovl_h , 
									int mem_x , int mem_y , int mem_w , int mem_h , 
									int imWidth , int imHeight,int stepW , int stepH);
int rk_overlay_hwcursor_getfbavglen();
int rk_overlay_setOvlAddr(int index);
int rk_overlay_CacheUpdate(char **data , int numCache);
void rk_overlay_getOverlayVirAddr(char **_overlayAddr_fb1_1 , char **_overlayAddr_fb1_2 , char ** _overlayAddr_fb1_hwc);
void rk_overlay_getOverlayinfo(SHMOVERLAYINFO *shmOverlayInfo);
int rk_overlay_getHwcHighestGrade();
int rk_overlay_getOverHighestGrade();


char * rk_overlay_getfbmem(int *fb_width , int *fb_height);


int rk_hwcursor_setEnable(bool enable);
int rk_hwcursor_setCurFormat(int x , int y , int sizeformat , int pixformat);
int rk_hwcursor_CacheUpdate(char *data , int size);




int rk_overlay_shmdemo_exec();
int rk_overlay_shm_gradesync();
int rk_overlay_shmdemo_create();

int rk_overlay_displayHWCfromX11Event(bool enable , Window winId ,Window xrdpwinId,  int rootStartX , int rootStartY , int rootEndX , int rootEndY);
int rk_overlay_freerdpSetPointer(int xhotspot , int yhotspot , int w , int h , int xorBpp , char *andMaskData , char *xorMaskData , int isVisual );
void  maskTcursorImageFromWin(cursor_tcp * cursorTcp , char *bmMask, char *bmColor ,  char ** maskOut , int *boColorBgra  );





int rk_overlay_display_nvTyuv(int dec_x, int dec_y ,int dec_width , int dec_height , 
										int src_x , int src_y ,int src_width , int src_height , 
										char **data , int width, int height ,int stepW , int stepH, int format );
int rk_overlay_display_ex(int dec_x, int dec_y ,int dec_width , int dec_height , 
						  int src_x , int src_y ,int src_width , int src_height , 
						  char **data , int width, int height , int stepW , int stepH, int format );

//==============extra================//
char * rk_overlay_getRdpRfxTmpShmBuf();
int rk_overlay_startCheckVncStatusDeamon(int gostart);
int rk_overlay_getVncStatusSign(int isLastUpdateSign);
int rk_overlay_getVncStatusAndupdateSign();
unsigned int rk_overlay_getcurtime(int type);

#endif//RK322_OVERLAYAPI_H

